// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import iView from 'iview';
import i18n from './libs/vuei18n.js';
import 'iview/dist/styles/iview.css';
import vueLoading from './libs/loadingOverlay.js';
import '@/css/index.less';
import http from '@/js/http.js'
import until from '@/js/until.js'
import dictionary from '@/js/dictionary.js'
import config from '@/config'
import store from './store'
import localStore from 'store';
import selectCountryArea from '@/components/selectCountryArea/selectCountryArea.vue';

import COS from 'cos-js-sdk-v5';

Vue.prototype.$http = http
Vue.prototype.$config = config
Vue.prototype.$dictionary = dictionary
Vue.prototype.$selfGlobal = {
    $globalStore: store,
    $globalI18n: i18n,
    $globalRequestMeth: {
        request: true,
        methodList: [],
    },
};
until.phoneType() == 'PC' ? until.websiteAdaptive() : until.adaptive()

Vue.prototype.$localStore = localStore;

Vue.config.productionTip = false
Vue.use(iView, {
    i18n: (key, value) => i18n.t(key, value)
});
Vue.component('selectCountryArea', selectCountryArea)

// 全局确认对话框
let modalCon = function (text) {
    return new Promise((resolve, reject) => {
        this.$Modal.confirm({
            title: this.$i18n.tc('views.public.prompt'),
            okText: this.$i18n.tc('views.public.sure'),
            cancelText: this.$i18n.tc('views.public.cancel'),
            content: text,
            onOk: () => {
                resolve(true)
            },
            onCancel: () => {
                resolve(false)
            }
        })
    })
}
//设置 “国家区域” 的选项
let getglobalRegion = function (type) {
    var text = null;
    var list = [
        {id: -1, text: this.$i18n.t("views.ltv.search2opt1")},
        {id: 0, text: this.$i18n.t("views.ltv.table2Text8")},
        {id: 1, text: this.$i18n.t("views.ltv.table2Text6")},
        {id: 3, text: this.$i18n.t("views.ltv.table2Text4")},
        {id: 4, text: this.$i18n.t("views.ltv.table2Text5")},
        {id: 5, text: this.$i18n.t("views.ltv.table2Text10")},
        {id: 6, text: this.$i18n.t("views.ltv.table2Text9")},
        {id: 9, text: this.$i18n.t("views.aboutAd.table1Text7")},
        {id: 10, text: this.$i18n.t("views.ltv.table2Text12")},
        {id: 11, text: this.$i18n.t("views.ltv.table2Text13")},
    ];
    list.forEach((item) => {
        if (Number(type) == Number(item.id)) {
            text = item.text
        }
    })
    return text || list
}


function getLocal(type) {
    return JSON.parse(localStorage.getItem(type));
}

function interfaceRegional(msg = {region: undefined, noList: undefined, noInt: false, additional: undefined}) {
    // region  获取区域名称
    // noList  需要过滤的区域
    // noInt  转字符串
    // additional  接口暂时不返回的
    const {region, noList, noInt, additional} = msg;
    var additionalList = [
        {id: 13, text: '波斯语'},
    ]

    let list = getLocal("interfaceRegional");
    console.log(list)
    if (Array.isArray(additional)) {
        additionalList.forEach((item) => {
            if (additional.includes(Number(item.id))) {
                list.splice(list.length - 1, 0, item)
            }
        })
    }
    if (noInt) {
        list.forEach((item) => {
            item.id = item.id + ''
        })
    }
    let newArray = []

    let results = [];
    let nameList = [];
    if (Array.isArray(region)) {
        for (let i in region) {
            results.push(list.find(item => item.id === Number(region[i])));
        }
    } else {
        let reg = region + ''
        results.push(list.find(item => item.id === Number(reg)));
    }
    results.forEach(item => {
        if (item) {
            nameList.push(item.text);
        }
    });

    if (Array.isArray(noList)) {
        list.forEach((item) => {
            if (!noList.includes(Number(item.id))) {
                newArray.push(item)
            }
        })
    }

    return region !== undefined ? nameList.join() : Array.isArray(noList) ? newArray : list;

}

// 数据列表校验数据  // zhangyang:@rName 参数用来兼容一些新窗口打开的，拿不到country_ids的情况
function autheCountry(type=1,rName) {
  // type等于1 获取配置的国家 2获取配置的权限
  //   console.log(rName)
    let routeName = rName ? rName :this.$route.name;
    // console.log(routeName)
    const allJurisdiction = JSON.parse(localStorage.getItem('allJurisdiction')) || {};
    let configuration = allJurisdiction[routeName];
    // console.log(configuration)
    if(configuration){
        localStorage.setItem('permissionsPage', configuration.permissionsPage);
        localStorage.setItem('autheCountry', configuration.country_ids);
        if(type==2){
            return configuration.permissionsPage
        }else {
            return configuration.country_ids
        }

    }

}

Vue.prototype.$modalCon = modalCon;
Vue.prototype.$getglobalRegion = getglobalRegion;
Vue.prototype.$interfaceRegional = interfaceRegional;
Vue.prototype.$autheCountry = autheCountry;


/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    store,
    i18n,
    components: {App},
    template: '<App/>'
})
